package org.example.deal;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class DealTest {


    public static void main(String[] args) {
        List<Deal> dealList = new ArrayList<>();


        //初始化数据
        dealList.add(new Deal(2020, 1000, DealType.RMB));
        dealList.add(new Deal(2020, 2000, DealType.RMB));

        dealList.add(new Deal(2020, 3000, DealType.DOLLAR));

        //21.对交易按照货币分组
        Map<DealType, List<Deal>> dealTypeMap = dealList.stream().collect(Collectors
                .groupingBy(it -> it.getDealType(), Collectors.toList()));

        for (Map.Entry<DealType, List<Deal>> entry : dealTypeMap.entrySet()) {
            List<Deal> deals = entry.getValue();

            DealType dealType = entry.getKey();
            System.out.println("交易类型：" + dealType.name() + ",交易数据：" + deals);
        }
    }
}
